package com.brainhealth.web.controller.customer;

import com.brainhealth.common.annotation.Anonymous;
import com.brainhealth.common.core.controller.BaseController;
import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.common.core.page.TableDataInfo;
import com.brainhealth.common.utils.DateUtils;
import com.brainhealth.common.utils.poi.ExcelUtil;
import com.brainhealth.customer.domain.*;
import com.brainhealth.customer.domain.vo.*;
import com.brainhealth.customer.service.IBuriedPointService;
import com.brainhealth.customer.service.ISysBuriedPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author wll
 */
@RestController
@RequestMapping("/customer/buried_point/v1")
public class BuriedPointController extends BaseController {

    @Autowired
    ISysBuriedPointService sysBuriedPointService;

    @Autowired
    IBuriedPointService  buriedPointBean;

    @Anonymous
    @PostMapping("/add")
    public AjaxResult addBuriedPoint(HttpServletRequest request,@RequestBody BuriedPointParam buriedPointParam) {
        Integer result = sysBuriedPointService.addBuriedPoint(request, buriedPointParam);
        if (null == result) {
            return error();
        }
        return success(result);
    }

    @Anonymous
    @PostMapping("/getPayTransformResult")
    public AjaxResult getPayTransformResult(@RequestBody BuriedPointQuery buriedPointQuery)
    {
        return success(sysBuriedPointService.getPayTransform(buriedPointQuery));
    }

    @Anonymous
    @PostMapping("/exportPayTransformResult")
    public void exportPayTransformResult(HttpServletResponse response,BuriedPointQuery buriedPointQuery)
    {
        List<PayTransformVO> payTransformList = sysBuriedPointService.getPayTransform(buriedPointQuery);
        ExcelUtil<PayTransformVO> util = new ExcelUtil<PayTransformVO>(PayTransformVO.class);
        String dateTime= DateUtils.dateTimeNow();
        util.exportExcel(response, payTransformList, "用户支付转化"+dateTime);
    }

    @Anonymous
    @PostMapping("/getRemainInfo")
    public AjaxResult getRemainInfo(@RequestBody BuriedPointQuery buriedPointQuery)
    {
        return success(sysBuriedPointService.getRemainInfo(buriedPointQuery));
    }

    /**
     * 导出动态列表的数据为excel文件
     * @param response
     * @param buriedPointQuery
     */
    @Anonymous
    @PostMapping("/dynamicExport")
    public void dynamicExport(HttpServletResponse response, @RequestBody BuriedPointQuery buriedPointQuery)
    {
        sysBuriedPointService.getDynamicRemainInfo(response, buriedPointQuery);
    }

    @Anonymous
    @PostMapping("/getPayInfo")
    public AjaxResult getPayInfo(@RequestBody BuriedPointQuery buriedPointQuery)
    {
        return success(sysBuriedPointService.getPayInfo(buriedPointQuery));
    }

    @Anonymous
    @PostMapping("/exportPayInfo")
    public void exportPayInfo(HttpServletResponse response,BuriedPointQuery buriedPointQuery)
    {
        List<PayInfoVO> payInfoList = sysBuriedPointService.getPayInfo(buriedPointQuery);
        ExcelUtil<PayInfoVO> util = new ExcelUtil<PayInfoVO>(PayInfoVO.class);
        String dateTime= DateUtils.dateTimeNow();
        util.exportExcel(response, payInfoList, "用户支付习惯统计"+dateTime);
    }

     @Anonymous
     @PostMapping("/getTrainInfo")
     public AjaxResult getTrainInfo(@RequestBody BuriedPointQuery buriedPointQuery)
     {
         return success(sysBuriedPointService.getTrainInfo(buriedPointQuery));
     }

    @Anonymous
    @PostMapping("/exportTrainInfo")
    public void exportTrainInfo(HttpServletResponse response,BuriedPointQuery buriedPointQuery)
    {
        List<TrainInfoVO> trainInfoVOList = sysBuriedPointService.getTrainInfo(buriedPointQuery);
        ExcelUtil<TrainInfoVO> util = new ExcelUtil<TrainInfoVO>(TrainInfoVO.class);
        String dateTime= DateUtils.dateTimeNow();
        util.exportExcel(response, trainInfoVOList, "完结用户留存统计"+dateTime);
    }

     @Anonymous
     @PostMapping("/getSysBuriedPointList")
     public TableDataInfo getSysBuriedPointList(@RequestBody BuriedPointQuery buriedPointQuery)
     {
         startPage();
         List<SysBuriedPoint> sysBuriedPointList = sysBuriedPointService.getBuriedPointList(buriedPointQuery);
         List<SysBuriedPointVO> sysBuriedPointVOList = sysBuriedPointService.getSysBuriedPointVO(sysBuriedPointList);

         return getDataTableNew(sysBuriedPointVOList,sysBuriedPointList);
     }

    @Anonymous
    @PostMapping("/export")
    public void exportSysBuriedPointList(HttpServletResponse response, BuriedPointQuery buriedPointQuery)
    {
        List<SysBuriedPointVO> sysBuriedPointVOList = sysBuriedPointService.getSysBuriedPointList(buriedPointQuery);
        ExcelUtil<SysBuriedPointVO> util = new ExcelUtil<SysBuriedPointVO>(SysBuriedPointVO.class);
        String dateTime= DateUtils.dateTimeNow();
        util.exportExcel(response, sysBuriedPointVOList, "埋点数据"+dateTime);
    }

    @Anonymous
    @PostMapping("/insertBuriedPointResult")
    public void insertBuriedPointResult(  String date)
    {
        buriedPointBean.insertBuriedPointResult(date);
    }

    @Anonymous
    @PostMapping("/addUserEventBuriedPoint")
    public AjaxResult addUserEventBuriedPoint(HttpServletRequest request,@RequestBody UserEventBuriedPointParam userEventBuriedPointParam) {
        return success(sysBuriedPointService.addUserEventBuriedPoint(request, userEventBuriedPointParam));
    }

    @Anonymous
    @PostMapping("/getUserOnlineTime")
    public AjaxResult getUserOnlineTime(@RequestBody UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        return success(sysBuriedPointService.getUserOnlineTime(userEventBuriedPointQueryParam));
    }

    @Anonymous
    @PostMapping("/getUserOnlineTimeDetail")
    public TableDataInfo getUserOnlineTimeDetail(@RequestBody UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        startPage();
        List<UserOnlineTimeDetail> userOnlineTimeDetailList = sysBuriedPointService.getUserOnlineTimeDetailList(userEventBuriedPointQueryParam);
        return getDataTable(userOnlineTimeDetailList);
    }

    @Anonymous
    @PostMapping("/exportUserOnlineTime")
    public void exportUserOnlineTime(HttpServletResponse response,UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        List<UserOnlineTimeDetail> userOnlineTimeDetailList = sysBuriedPointService.getUserOnlineTimeDetailList(userEventBuriedPointQueryParam);
        ExcelUtil<UserOnlineTimeDetail> util = new ExcelUtil<UserOnlineTimeDetail>(UserOnlineTimeDetail.class);
        String dateTime= DateUtils.dateTimeNow();
        util.exportExcel(response, userOnlineTimeDetailList, "用户在线时长"+dateTime);
    }

    @Anonymous
    @PostMapping("/getUserOnlineTimeStatus")
    public AjaxResult getUserOnlineTimeStatus(@RequestBody UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        return success(sysBuriedPointService.getUserOnlineTimeStatus(userEventBuriedPointQueryParam));
    }

    @Anonymous
    @PostMapping("/getUserOnlineTimeStatusDetail")
    public TableDataInfo getUserOnlineTimeStatusDetail(@RequestBody UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        startPage();
        List<UserOnlineTimeStatusDetail> userOnlineTimeStatusDetailList = sysBuriedPointService.getUserOnlineTimeStatusDetailList(userEventBuriedPointQueryParam);
        return getDataTable(userOnlineTimeStatusDetailList);
    }

    @Anonymous
    @PostMapping("/exportUserOnlineTimeStatus")
    public void exportUserOnlineTimeStatus(HttpServletResponse response,UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        List<UserOnlineTimeStatusDetail> userOnlineTimeDetailList = sysBuriedPointService.getUserOnlineTimeStatusDetailList(userEventBuriedPointQueryParam);
        ExcelUtil<UserOnlineTimeStatusDetail> util = new ExcelUtil<UserOnlineTimeStatusDetail>(UserOnlineTimeStatusDetail.class);
        String dateTime= DateUtils.dateTimeNow();
        util.exportExcel(response, userOnlineTimeDetailList, "用户在线时长(状态)"+dateTime);
    }

    @Anonymous
    @PostMapping("/getUserOnlineFrequency")
    public AjaxResult getUserOnlineFrequency(@RequestBody UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        return success(sysBuriedPointService.getUserOnlineFrequency(userEventBuriedPointQueryParam));
    }

    @Anonymous
    @PostMapping("/getUserOnlineFrequencyDetail")
    public TableDataInfo getUserOnlineFrequencyDetail(@RequestBody UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        startPage();
        List<UserOnlineFrequencyDetail> userOnlineFrequencyDetailList = sysBuriedPointService.getUserOnlineFrequencyDetailList(userEventBuriedPointQueryParam);
        return getDataTable(userOnlineFrequencyDetailList);
    }

    @Anonymous
    @PostMapping("/exportUserOnlineFrequency")
    public void exportUserOnlineFrequency(HttpServletResponse response,UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        List<UserOnlineFrequencyDetail> userOnlineFrequencyDetailList = sysBuriedPointService.getUserOnlineFrequencyDetailList(userEventBuriedPointQueryParam);
        ExcelUtil<UserOnlineFrequencyDetail> util = new ExcelUtil<UserOnlineFrequencyDetail>(UserOnlineFrequencyDetail.class);
        String dateTime= DateUtils.dateTimeNow();
        util.exportExcel(response, userOnlineFrequencyDetailList, "用户在线频次"+dateTime);
    }

    @Anonymous
    @PostMapping("/getUserOnlineFrequencyStatus")
    public AjaxResult getUserOnlineFrequencyStatus(@RequestBody UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        return success(sysBuriedPointService.getUserOnlineFrequencyStatus(userEventBuriedPointQueryParam));
    }

    @Anonymous
    @PostMapping("/getUserOnlineFrequencyStatusDetail")
    public TableDataInfo getUserOnlineFrequencyStatusDetail(@RequestBody UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        startPage();
        List<UserOnlineFrequencyStatusDetail> userOnlineFrequencyDetailStatusList = sysBuriedPointService.getUserOnlineFrequencyDetailStatusList(userEventBuriedPointQueryParam);
        return getDataTable(userOnlineFrequencyDetailStatusList);
    }

    @Anonymous
    @PostMapping("/exportUserOnlineFrequencyStatus")
    public void exportUserOnlineFrequencyStatus(HttpServletResponse response, UserEventBuriedPointQueryParam userEventBuriedPointQueryParam) {
        List<UserOnlineFrequencyStatusDetail> userOnlineFrequencyDetailList = sysBuriedPointService.getUserOnlineFrequencyDetailStatusList(userEventBuriedPointQueryParam);
        ExcelUtil<UserOnlineFrequencyStatusDetail> util = new ExcelUtil<UserOnlineFrequencyStatusDetail>(UserOnlineFrequencyStatusDetail.class);
        String dateTime= DateUtils.dateTimeNow();
        util.exportExcel(response, userOnlineFrequencyDetailList, "用户在线频次(状态)"+dateTime);
    }

    @Anonymous
    @PostMapping("/insertUserEventBuriedPointResult")
    public void insertUserEventBuriedPointResult(String date) {
        sysBuriedPointService.insertUserEventBuriedPointResult(date);
    }
}
